export function prettyFormatNumber(num) {
  const units = ['次', '万', '亿'];
  if (num < 10000) {
    return num + '次';
  } else {
    let unitIndex = 0;
    while (num >= 10000 && unitIndex < units.length - 1) {
      num /= 10000;
      unitIndex++;
    }
    return num.toFixed(unitIndex === 0 ? 0 : 1) + units[unitIndex];
  }
}

/**
	 * 剩余时间格式化
	 * @param {Number} t - 剩余多少秒
	 * @return {Object}  formatDate - 格式后的天时分秒对象
	 */
export function formatDate(t) {
  let format = {
    d: '00',
    h: '00',
    m: '00',
    s: '00',
  };
  if (t > 0) {
    let d = Math.floor(t / 86400);
    let h = Math.floor((t / 3600) % 24);
    let m = Math.floor((t / 60) % 60);
    let s = Math.floor(t % 60);
    format.d = d < 10 ? '0' + d : d;
    format.h = h < 10 ? '0' + h : h;
    format.m = m < 10 ? '0' + m : m;
    format.s = s < 10 ? '0' + s : s;
  }
  return format;
}